﻿///////////////////////////////////////
//////add by yl 2014年8月20日14:01:31
//////主要功能:处理班组设备报修
///////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Catering_DBOpertion;

namespace Catering_Model
{
    /// <summary>
    /// EMASppPlan:班组设备报修单
    /// </summary>
    [Serializable]
    public partial class EquipmentAndFacility
    {
        public EquipmentAndFacility()
        { }
        #region Model
        private int _id;
        private string _PName;
        private string _PType;
        private string _Person;
        private string _zhouqi;
        private int _ClassId;
        private DateTime _SaveDate;
        
        /// <summary>
        /// 
        /// </summary>
        public int Id
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 日报管理编号
        /// </summary>
        public string PName
        {
            set { _PName = value; }
            get { return _PName; }
        }
        /// <summary>
        /// 作业区编号
        /// </summary>
        public string PType
        {
            set { _PType = value; }
            get { return _PType; }
        }
        /// <summary>
        /// 班组编号
        /// </summary>
        public string Person
        {
            set { _Person = value; }
            get { return _Person; }
        }
        /// <summary>
        /// 设备名称
        /// </summary>
        public string zhouqi
        {
            set { _zhouqi = value; }
            get { return _zhouqi; }
        }

        /// <summary>
        /// 设备型号
        /// </summary>
        public int ClassId
        {
            set { _ClassId = value; }
            get { return _ClassId; }
        }
        /// <summary>
        /// 品牌产地
        /// </summary>
        public DateTime SaveDate
        {
            set { _SaveDate = value; }
            get { return _SaveDate; }
        }
      
        #endregion Model
    }
}
namespace Catering_Rules
{
    /// <summary>
    /// Moon
    /// </summary>
    public partial class EquipmentAndFacility
    {
        private readonly Catering_Operation.EquipmentAndFacility dal = new Catering_Operation.EquipmentAndFacility();
        public EquipmentAndFacility()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Id)
        {
            return dal.Exists(Id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Catering_Model.EquipmentAndFacility model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Catering_Model.EquipmentAndFacility model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id)
        {

            return dal.Delete(Id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            return dal.DeleteList(Idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.EquipmentAndFacility GetModel(int Id)
        {

            return dal.GetModel(Id);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Catering_Model.EquipmentAndFacility> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Catering_Model.EquipmentAndFacility> DataTableToList(DataTable dt)
        {
            List<Catering_Model.EquipmentAndFacility> modelList = new List<Catering_Model.EquipmentAndFacility>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Catering_Model.EquipmentAndFacility model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = dal.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}
namespace Catering_Operation
{
    /// <summary>
    /// 数据访问类:Moon
    /// </summary>
    public partial class EquipmentAndFacility
    {
        public EquipmentAndFacility()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Moon");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Catering_Model.EquipmentAndFacility model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into EquipmentAndFacility(");
            strSql.Append("PName,PType,Person,zhouqi,ClassId,SaveDate)");
            strSql.Append(" values (");
            strSql.Append("@PName,@PType,@Person,@zhouqi,@ClassId,@SaveDate)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@PName", SqlDbType.VarChar,50),
                    new SqlParameter("@PType", SqlDbType.VarChar,50),
                    new SqlParameter("@Person", SqlDbType.VarChar,50),
					new SqlParameter("@zhouqi", SqlDbType.VarChar,50),
					new SqlParameter("@ClassId", SqlDbType.Int,4),					
					new SqlParameter("@SaveDate", SqlDbType.Date,-1)};
            parameters[0].Value = model.PName;
            parameters[1].Value = model.PType;
            parameters[2].Value = model.Person;
            parameters[3].Value = model.zhouqi;
            parameters[4].Value = model.ClassId;
            parameters[5].Value = model.SaveDate;


            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Catering_Model.EquipmentAndFacility model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update EquipmentAndFacility set ");
            strSql.Append("PName=@PName,");
            strSql.Append("PType=@PType,");
            strSql.Append("Person=@Person,");
            strSql.Append("zhouqi=@zhouqi");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@PName", SqlDbType.VarChar,50),
                    new SqlParameter("@PType", SqlDbType.VarChar,50),                    
                    new SqlParameter("@Person", SqlDbType.VarChar,50),
                    new SqlParameter("@zhouqi", SqlDbType.VarChar,50),
                    new SqlParameter("@Id", SqlDbType.Int,4)};
            parameters[0].Value = model.PName;
            parameters[1].Value = model.PType;
            parameters[2].Value = model.Person;
            parameters[3].Value = model.zhouqi;
            parameters[4].Value = model.Id;            

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from EquipmentAndFacility ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Moon ");
            strSql.Append(" where Id in (" + Idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.EquipmentAndFacility GetModel(int Id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,PName,PType,Person,zhouqi from EquipmentAndFacility");
            strSql.Append(" where id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,-1)
			};
            parameters[0].Value = Id;

            Catering_Model.EquipmentAndFacility model = new Catering_Model.EquipmentAndFacility();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.EquipmentAndFacility DataRowToModel(DataRow row)
        {
            Catering_Model.EquipmentAndFacility model = new Catering_Model.EquipmentAndFacility();
            if (row != null)
            {
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.Id = int.Parse(row["id"].ToString());
                }
                if (row["PName"] != null && row["PName"].ToString() != "")
                {
                    model.PName = row["PName"].ToString();
                }
                if (row["PType"] != null && row["PType"].ToString() != "")
                {
                    model.PType = row["PType"].ToString();
                }
                if (row["Person"] != null && row["Person"].ToString() != "")
                {
                    model.Person = row["Person"].ToString();
                }
                if (row["zhouqi"] != null && row["zhouqi"].ToString() != "")
                {
                    model.zhouqi = row["zhouqi"].ToString();
                }
                
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select *");
            strSql.Append(" FROM EquipmentAndFacility ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" Id,MoonName,ClassId,Remark ");
            strSql.Append(" FROM Moon ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM Moon ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.Id desc");
            }
            strSql.Append(")AS Row, T.*  from Moon T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "Moon";
            parameters[1].Value = "Id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}